{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Sankey"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# nodes=[{'name':'部门1','name':'部门2','name':'部门3','name':'部门4','name':'部门5','name':'部门6'},\n",
    "# {'name':'项目1','name':'项目2','name':'项目3','name':'项目4'}]\n",
    "nodes=[{'name':'部门1'},{'name':'部门2'},{'name':'部门3'},{'name':'部门4'},{'name':'部门5'},{'name':'部门6'},{'name':'项目1'},{'name':'项目2'},{'name':'项目3'},{'name':'项目4'},{'name':'项目5'},{'name':'项目6'},{'name':'项目7'},{'name':'项目8'},{'name':'项目9'},{'name':'项目10'}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "linkes=[{'source':'部门1','target':'项目1','value':100},{'source':'部门1','target':'项目2','value':20}, {'source':'部门1','target':'项目3','value':40},{'source':'部门1','target':'项目4','value':70},{'source':'部门1','target':'项目5','value':40},{'source':'部门1','target':'项目6','value':70},{'source':'部门1','target':'项目7','value':40},{'source':'部门1','target':'项目8','value':70},{'source':'部门1','target':'项目9','value':40},{'source':'部门1','target':'项目10','value':70},\n",
    "        {'source':'部门2','target':'项目1','value':10},{'source':'部门2','target':'项目2','value':50}, {'source':'部门2','target':'项目3','value':10},{'source':'部门2','target':'项目4','value':50}, {'source':'部门2','target':'项目5','value':10},{'source':'部门2','target':'项目6','value':50}, {'source':'部门2','target':'项目7','value':10},{'source':'部门2','target':'项目8','value':50}, {'source':'部门2','target':'项目9','value':10},{'source':'部门2','target':'项目10','value':50},\n",
    "        {'source':'部门3','target':'项目1','value':10},{'source':'部门3','target':'项目2','value':50},{'source':'部门3','target':'项目3','value':0},{'source':'部门3','target':'项目4','value':80}, {'source':'部门3','target':'项目5','value':10},{'source':'部门3','target':'项目6','value':50},{'source':'部门3','target':'项目7','value':0},{'source':'部门3','target':'项目8','value':80}, {'source':'部门3','target':'项目9','value':10},{'source':'部门3','target':'项目10','value':50},\n",
    "        {'source':'部门4','target':'项目1','value':40},{'source':'部门4','target':'项目2','value':20},{'source':'部门4','target':'项目3','value':33},{'source':'部门4','target':'项目4','value':40},{'source':'部门4','target':'项目5','value':33},{'source':'部门4','target':'项目6','value':40},{'source':'部门4','target':'项目7','value':33},{'source':'部门4','target':'项目8','value':40},{'source':'部门4','target':'项目9','value':33},{'source':'部门4','target':'项目10','value':40},\n",
    "        {'source':'部门5','target':'项目1','value':15},{'source':'部门5','target':'项目2','value':25},{'source':'部门5','target':'项目3','value':49},{'source':'部门5','target':'项目4','value':67},{'source':'部门5','target':'项目5','value':49},{'source':'部门5','target':'项目6','value':67},{'source':'部门5','target':'项目7','value':49},{'source':'部门5','target':'项目8','value':67},{'source':'部门5','target':'项目9','value':49},{'source':'部门5','target':'项目10','value':67},\n",
    "        {'source':'部门6','target':'项目1','value':55},{'source':'部门6','target':'项目2','value':35},{'source':'部门6','target':'项目3','value':17},{'source':'部门6','target':'项目4','value':28},{'source':'部门6','target':'项目5','value':17},{'source':'部门6','target':'项目6','value':28},{'source':'部门6','target':'项目7','value':17},{'source':'部门6','target':'项目8','value':28},{'source':'部门6','target':'项目9','value':17},{'source':'部门6','target':'项目10','value':28}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# linkes=[{'source':'部门1','target':'项目1','value':100},{'source':'部门1','target':'项目2','value':20},            {'source':'部门1','target':'项目3','value':40},{'source':'部门1','target':'项目4','value':70},\n",
    "#         {'source':'部门2','target':'项目1','value':10},{'source':'部门2','target':'项目2','value':50},\n",
    "#         {'source':'部门2','target':'项目3','value':0},{'source':'部门2','target':'项目4','value':80},\n",
    "#         {'source':'部门3','target':'项目1','value':10},{'source':'部门3','target':'项目2','value':50},\n",
    "#         {'source':'部门3','target':'项目3','value':0},{'source':'部门3','target':'项目4','value':80},\n",
    "#         {'source':'部门4','target':'项目1','value':40},{'source':'部门4','target':'项目2','value':20},\n",
    "#         {'source':'部门4','target':'项目3','value':33},{'source':'部门4','target':'项目4','value':40},\n",
    "#         {'source':'部门5','target':'项目1','value':15},{'source':'部门5','target':'项目2','value':25},\n",
    "#         {'source':'部门5','target':'项目3','value':49},{'source':'部门5','target':'项目4','value':67},\n",
    "#         {'source':'部门6','target':'项目1','value':55},{'source':'部门6','target':'项目2','value':35},\n",
    "#         {'source':'部门6','target':'项目3','value':17},{'source':'部门6','target':'项目4','value':28}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "C:\\Python3_7_2\\lib\\site-packages\\pyecharts\\charts\\chart.py:14: PendingDeprecationWarning: pyecharts 所有图表类型将在 v1.9.0 版本开始强制使用 ChartItem 进行数据项配置 :)\n  super().__init__(init_opts=init_opts)\n"
     ]
    },
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "'f:\\\\PycharmOut\\\\SanKey\\\\test.html'"
      ]
     },
     "metadata": {},
     "execution_count": 15
    }
   ],
   "source": [
    "pic=(Sankey().add(\n",
    "    '',\n",
    "    nodes,\n",
    "    linkes,\n",
    "    pos_right='40%',\n",
    "    # pos_left='25%',\n",
    "    node_width=20,\n",
    "    layout_iterations=10,\n",
    "    itemstyle_opts=opts.ItemStyleOpts(border_width=1, border_color=\"#aaa\"),\n",
    "    linestyle_opt=opts.LineStyleOpts(opacity=0.3,curve=0.5,color='#EE7621'),\n",
    "    label_opts=opts.LabelOpts(position='right'),\n",
    "    node_gap=30,\n",
    "    ).set_global_opts(title_opts=opts.TitleOpts(title='项目工时资源流'))\n",
    ")\n",
    "pic.render('test.html')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}